package com.xuyiwei.mayi.test;

/**
 * Created by xuyiwei on 2019/5/6.
 */
class Obj {
    int i = 0;

    public int getI() {
        return i;
    }

    public void setI(int i) {
        this.i = i;
    }
}
class AtomicIntegerThread implements Runnable{
    Obj obj;

    public AtomicIntegerThread(Obj o) {
        this.obj = o;
    }

    @Override
    public void run() {

        int i =obj.getI()+1;
        obj.setI(i);
        System.out.print(obj.getI() +"     ");
    }
}
public class AtomicIntegerDemo {
    public static void main(String[] args) {
        Obj obj = new Obj();
        obj.setI(0);
        for(int i=0;i<10000;i++){
            Thread at = new Thread(new AtomicIntegerThread(obj));
            at.start();

        }
    }
}
